CC		= g++

SRCEXTS	= .cpp
HDREXTS	= .h

CFLAGS	= -O2 -Wall -Iinclude
LDFLAGS	= -Iinclude -lrt

ETAGS 	= etags
CTAGS 	= ctags

SRCDIRS	= src
INCDIR 	= include
OBJDIR	= bin

PROGRAM = perceptron

SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
HEADERS = $(foreach d,$(INCDIR),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
OBJS    = $(addsuffix .o, $(addprefix $(OBJDIR)/, $(basename $(SOURCES))))
DEPS    = $(OBJS:.o=.d)

.PHONY: all objs tags ctags clean clean_all show exec
.SUFFIXES:

all: $(PROGRAM)

objs: $(OBJDIR)/$(OBJS)

$(OBJDIR)/%.o:%.cpp $(HEADERS)
	mkdir $(dir $@) -p
	$(CC) -c $< -o $@ $(CFLAGS)
	
tags: $(HEADERS) $(SOURCES)
	$(ETAGS) $(HEADERS) $(SOURCES)

ctags: $(HEADERS) $(SOURCES)
	$(CTAGS) $(HEADERS) $(SOURCES)
	
$(PROGRAM):$(OBJS)
	$(CC) $(OBJS) -o $(OBJDIR)/$@ $(LDFLAGS)
	@echo Type ./$(OBJDIR)/$@ to execute the program.
	
ifndef NODEP
  ifneq ($(DEPS),)
    sinclude $(DEPS)
  endif
endif
	
clean:
	find bin -iname *.o -delete
	find bin -iname *.d -delete
	
clean_all:
	rm -R $(OBJDIR)
	
exec:
	./$(OBJDIR)/$(PROGRAM)

show:
	@echo 'PROGRAM     :' $(PROGRAM)
	@echo 'SRCDIRS     :' $(SRCDIRS)
	@echo 'OBJDIR      :' $(OBJDIR)
	@echo 'SOURCES     :' $(SOURCES)
	@echo 'HEADERS     :' $(HEADERS)
	@echo 'OBJS        :' $(OBJS)
	@echo 'DEPS        :' $(DEPS)
	@echo 'CFLAGS      :' $(CFLAGS)
	@echo 'LIBS        :' $(LIBS)
	
